﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmPlanDeviceList : FrmBase
    {
        private List<PlanDevice> planDevices;
        private string workType;

        public FrmPlanDeviceList()
        {
            InitializeComponent();

            ttlbrhead.Text = "巡视设备选择";
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.返回01);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.返回02);

            btnPrior.UpImage = ResourceImage.上一页可点击;
            btnPrior.DownImage = ResourceImage.上一页点击;
            btnPrior.DisableImage = ResourceImage.上一页灰;
            btnNext.UpImage = ResourceImage.下一页可点击;
            btnNext.DownImage = ResourceImage.下一页点击;
            btnNext.DisableImage = ResourceImage.下一页灰;
        }

        private void FrmPlanDeviceSelect_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            dlPlanDevices.DisplayMember = "DeviceName";
            dlPlanDevices.DataSource = planDevices;
            dlPlanDevices.DataBind();

            SetButtonState();
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            planDevices = (List<PlanDevice>)Parameter[0];
            workType = (string)Parameter[1];
        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            planDevices = (List<PlanDevice>)Caches[0];
            workType = (string)Caches[1];
        }

        private void bcOperate_OnButtonClick(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 0:  //确定
                    break;
                case 2: //返回
                    FormManage.GotoNext("FrmPlanDeviceSelect", null, null, true);
                    break;


            }
        }

        private void dlPlanDevices_OnItemClick(HandRise.MBHOP.Controls.DataListItem item)
        {
            PlanDevice planDevice = (PlanDevice)item.DataSource;
            FormManage.GotoNext("FrmPatrolPoint", new object[] { "FrmPlanDeviceList", planDevice, workType }, new object[] { planDevices, workType }, false);
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            dlPlanDevices.NextPage();
            SetButtonState();
        }

        private void btnPrior_Click(object sender, EventArgs e)
        {
            dlPlanDevices.PreviousPage();
            SetButtonState();
        }

        private void SetButtonState()
        {
            btnNext.Enabled = dlPlanDevices.PageCount > 0 && dlPlanDevices.PageIndex < dlPlanDevices.PageCount;
            btnPrior.Enabled = dlPlanDevices.PageCount > 0 && dlPlanDevices.PageIndex > 1;
        }
     }
}